package com.haredot.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.haredot.validation.Update;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 
 * @TableName tb_resource
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value ="tb_resource")
public class Resource implements Serializable {
    @Serial
    private static final long serialVersionUID = -8608807775655750199L;
    /**
     * 
     */
    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "资源ID不允许为空", groups = Update.class)
    private Long id;

    /**
     * 资源名
     */
    @NotEmpty(message = "资源名不允许为空")
    private String resourceName;

    /**
     * 资源路径
     */
    @NotEmpty(message = "资源不允许为空")
    private  String url;

    /**
     * 资源描述
     */
    private  String resourceDesc;

    /**
     * 关键字，多个以::分割
     */
    @NotEmpty(message = "关键字不允许为空")
    private  String keywords;

    /**
     * 资源分类ID
     */
    @NotNull(message = "资源类型不允许为空")
    @JsonSerialize(using = ToStringSerializer.class)
    private  Long typeId;

    /**
     * 上传者
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private  Long userId;

    /**
     * 资源积分
     */
    @NotNull(message = "积分不允许为空")
    @Range(min = 0, max = 10, message = "积分超出 0 ~ 10 范围")
    private Integer score;

    /**
     * 资源大小
     */
    @NotNull(message = "资源大小不允许为空")
    private Long size;

    /**
     * 资源扩展名
     */
    private String ext;

    /**
     * 资源状态， 0 未审核、1 审核通过、-1 审核未通过
     */
    private  Integer state;

    /**
     * 审核失败原因
     */
    private  String reason;

    /**
     * 审核人员
     */
    private  String user;

    /**
     * 是否是精选资源，默认否
     */
    private  Boolean core;

    /**
     * 录入时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private  LocalDateTime createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private  LocalDateTime updateTime;

    /**
     * 删除标记
     */
    private  Boolean del;

}